/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package ec.edu.espe.ccsoft.mantenimiento.dao;

import ec.edu.espe.ccsoft.mantenimiento.modelos.Bodega;
import ec.edu.espe.ccsoft.mantenimiento.modelos.Pais;
import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

/**
 *
 * @author misahaelfernandez
 */
@Stateless
public class BodegaFacade extends AbstractFacade<Bodega> {

    @PersistenceContext(unitName = "ec.edu.espe.ccsoft_CCSoftMantenimiento-ejb_ejb_1PU")
    private EntityManager em;

    @Override
    protected EntityManager getEntityManager() {
        return em;
    }

    public BodegaFacade() {
        super(Bodega.class);
    }

    public List<Bodega> findByEstado(Boolean bool) {
        Query consulta = this.em.createQuery("SELECT u FROM Bodega u "
                + "WHERE u.estado=?1");
        consulta.setParameter(1, bool);
        return consulta.getResultList();
    }

    public Bodega FindByNombre(String nombre) {
        Query consulta = this.em.createQuery("SELECT u FROM Bodega u "
                + "WHERE u.nombre=?1");
        consulta.setParameter(1, nombre);
        return consulta.getResultList().isEmpty() ? null : (Bodega) consulta.getSingleResult();

    }

}
